package com.sso.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.base.utils.IdUtils;
import com.sso.entity.DicSystem;
import com.sso.service.IDicSystemService;
@ManagedBean(name = "sso_addSystemBean", scope = ManagedBeanScope.REQUEST)
public class AddSystemBean {
	protected IDicSystemService dicSystemService = SpringBeanHolder
	.getBean("dicSystemService");
	
	@Bind
	@Accessible
	@SaveState
	String id;
	@Bind
	@Accessible
	@SaveState
	protected String systemID;
	protected DicSystem system;
	// 系统名称
	@Bind(id = "systemName", attribute = "value")
	protected String systemName;
	// 描述
	@Bind(id = "systemRemark", attribute = "value")
	protected String systemRemark;
	//系统地址
	@Bind(id = "systemUrl", attribute = "value")
	protected String systemUrl;
	//系统服务地址
	@Bind(id = "systemServiceAddress", attribute = "value")
	protected String systemServiceAddress;
	
	@Inject
	private FacesContext context;

	@SaveState
	private String first;
	
	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			id = IdUtils.getUUID();
		}
	}
	
	@Action(id = "save")
	public void save() {
		system = new DicSystem();
		system.setId(id);
		system.setSystemName(systemName);
		system.setSystemRemark(systemRemark);
		system.setSystemUrl(systemUrl);
		system.setSystemServiceAddress(systemServiceAddress);
		dicSystemService.saveDicSystem(system);
		Browser
				.execClientScript("javascript:closeCenterLayoutTab('addSystemTab')");
	}
}
